package com.dongline.test.gongtonghaoyou;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;
import java.util.Arrays;

public class Friend2Mapper extends Mapper<LongWritable, Text,Text,Text> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        FileSplit inputSplit = (FileSplit) context.getInputSplit();
        if(inputSplit.getPath().getName().startsWith("part"))
        {
            String []person_friends=value.toString().split("\t,");
            String [] friends=person_friends[1].split(",");




            Arrays.sort(friends);
            for (int i=0;i<friends.length-1;i++)
            {
                for (int j=1+i;j<friends.length-1;j++)
                {
                    context.write(new Text(friends[i]+"-"+friends[j]),new Text(person_friends[0]));
                }
            }
        }


    }
}
